package com.pan.admin.module.loanUser.entity.vo;

import com.pan.admin.common.annotation.Excel;
import com.pan.admin.common.core.domain.BaseEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 用户资质列表
 * @Author: ghb
 * @Date: 2023/10/16 9:58
 */
@Data
public class LoanUserFormFieldVo extends BaseEntity {

    /**
     * 字段主键
     */
    @Excel(name = "字段主键")
    private Long fieldId;

    /**
     * 字段值主键
     */
    @Excel(name = "字段值主键")
    private Long fieldValueId;

    /**
     * 用户主键
     */
    @Excel(name = "用户主键")
    private Long userId;

    /**
     * 用户账户
     */
    @Excel(name = "用户账户")
    private String userName;

    /**
     * 用户账户
     */
    @Excel(name = "用户账户")
    private String idcard;

    /**
     * 用户手机
     */
    @Excel(name = "用户手机")
    private String phone;

    /**
     * 字段名称
     */
    @Excel(name = "字段名称")
    private String fieldName;

    /**
     * 字段值
     */
    @Excel(name = "字段值名称")
    private String fieldValue;

    /**
     * 默认0（其他类型） 1基本信息类型， 2资产类型
     */
    @Excel(name = "默认0", readConverterExp = "其=他类型")
    private Long type;

    /**
     * 渠道名称
     */
    @Excel(name = "渠道名称")
    private String channelName;

    private Long loanChannelId;

    private List<Map<String, String>> map;

    private Integer loanProductId;


    public List<LoanUserFormFieldVo> distinct(List<LoanUserFormFieldVo> list) {
        // 初始化结果数据
        Map<String, Map<String, Object>> processedData = new HashMap<>();
        List list1 = new ArrayList<>();
        // 将数据库查询结果逐个添加到processedData中
        for (LoanUserFormFieldVo data : list) {
            String phone = data.getPhone();
            // 如果该手机号还没有对应的结果数据，则初始化一个空的Map
            if (!processedData.containsKey(phone)) {
                Map<String, Object> userData = new HashMap<>();
                processedData.put(phone, userData);
            }
            // 添加字段值到对应的结果数据中
            String fieldId = data.getFieldId().toString();
            String fieldValue = data.getFieldValue();
            processedData.get(phone).put(fieldId, fieldValue);
            processedData.get(phone).put("phone", phone);
        }
        // 输出处理后的数据
        for (String phone : processedData.keySet()) {
            Map<String, Object> userData = processedData.get(phone);
            list1.add(userData);
            System.out.println(userData);
        }
        return list1;
    }

    public Long getLoanChannelId() {
        return loanChannelId;
    }

    public void setLoanChannelId(Long loanChannelId) {
        this.loanChannelId = loanChannelId;
    }

    public List<Map<String, String>> getMap() {
        return map;
    }

    public void setMap(List<Map<String, String>> map) {
        this.map = map;
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public Integer getLoanProductId() {
        return loanProductId;
    }

    public void setLoanProductId(Integer loanProductId) {
        this.loanProductId = loanProductId;
    }

    public Long getFieldId() {
        return fieldId;
    }

    public void setFieldId(Long fieldId) {
        this.fieldId = fieldId;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public Long getFieldValueId() {
        return fieldValueId;
    }

    public void setFieldValueId(Long fieldValueId) {
        this.fieldValueId = fieldValueId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldValue() {
        return fieldValue;
    }

    public void setFieldValue(String fieldValue) {
        this.fieldValue = fieldValue;
    }

    public Long getType() {
        return type;
    }

    public void setType(Long type) {
        this.type = type;
    }
}
